package com.zj.aopspringboot01;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component //将切面类声明为一个bean
@Aspect //声明这是一个切面类
public class LogAspect {
    @Around("execution(* com.zj.aopspringboot01.UserService.*(..))") //声明这是一个环绕通知
    public Object logAdd(ProceedingJoinPoint pj) {
        //前置通知部分
        System.out.println("start: " + pj.getSignature());
        Object res = null;
        try {
            res = pj.proceed();
        } catch (Throwable e) {
            //异常通知部分
            System.out.println("exception = " + e.getMessage());
        }finally {
            //后置通知也叫最终通知部分
            System.out.println("finally: " + pj.getSignature());
        }
        //返回通知部分
        System.out.println("end " + pj.getTarget());
        System.out.println("end " + pj.getThis());
        System.out.println("end " + pj.getKind());
        System.out.println("end " + pj.getStaticPart());
        System.out.println("end " + pj.getSourceLocation());
        System.out.println("end " + res);
        return  res;
    }
}
